home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / lcppb.zip / LCPPANS.ZIP / TAB4.CPP < prev    next >
C/C++ Source or Header  |  1991-07-08  |  860b  |  46 lines

  1. // tab4.cpp -- Display text with 4-column tabs
  2.  
  3. #include <iostream.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. #define TABSTOP 5        // 5 == 4-column tabs
  8.  
  9. main(int argc, char *argv[])
  10. {
  11.   FILE *fp;
  12.   char c;
  13.   int count;
  14.  
  15.   if (argc == 1) {
  16.     cout << "ERROR: No file name";
  17.     exit(1);
  18.   }
  19.   fp = fopen(argv[1], "r");
  20.   if (!fp) {
  21.     cout << "ERROR: File not found";
  22.     exit(2);
  23.   }
  24.   count = 1;
  25.   while ((c = fgetc(fp)) != EOF) {
  26.     if (c == '\t')
  27.       while ((++count % 5) != 1) cout << ' ';
  28.     else {
  29.       if (c == '\n')
  30.             count = 1;
  31.       else
  32.         count++;
  33.       cout << c;
  34.     }
  35.   }
  36.   fclose(fp);
  37. }
  38.  
  39.  
  40. // Copyright (c) 1990 by Tom Swan. All rights reserved
  41. // Revision 1.00    Date: 12/06/1990   Time: 10:47 am
  42.  
  43. // Revision 1.01    Date: 07/08/1991   Time: 05:41 pm
  44. // Converted for Borland C++ 2.0
  45.  
  46.